<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2018/2/24
 * Time: 10:35
 */

namespace app\console\controller;

use app\common\controller\Console;
use think\Cache;

class Option extends Console {

    public function _empty() {
        return $this->fetch();
    }

    public function add() {
        return $this->fetch();
    }

    public function update()
    {
        $option = request()->post( 'option/a' );

        if ( is_array( $option ) && ! empty( $option )  ) {
            $Options = model('Options');
            $cache_data = [];
            foreach ( $option as $name => $value ) {
                if ($name == 'cash_list') {
                    $value = str_replace("，",",",$value);
                }
                $where['name'] = $name;
                $data['value'] = is_array( $value ) ? json_encode( $value ) : $value;
                $Options->where( $where )->update( $data );
                $cache_data[$name] = $value;
            }
            Cache::store('redis')->set(config('system_config_name'), serialize($cache_data));
            $this->success( "操作成功。" );
        } else {
            $this->success( "错误的请求。" );
        }

    }
}
